package client_proxy

import (
	"awesomeProject3/new_helloworld/handler"
	"fmt"
	"net/rpc"
)

//只定义返回的类型  相当于构造方法
type HelloServiceStub struct {
	rpcs *rpc.Client
}

//在go语言中没有类、对象就意味着没有初始化方法
func NewHelloServiceClient(protol, address string) HelloServiceStub {
	conn, err := rpc.Dial(protol, address)
	if err != nil {
		//panic("connect error!")
		fmt.Println(err)
	}
	return HelloServiceStub{conn}
}

func (c *HelloServiceStub) Hello(request string, reply *string) error {
	err := c.rpcs.Call(handler.HelloServiceName+".Hello", request, reply)
	if err != nil {
		return err
	}
	return nil
}
